package com.boot.springboot.component.listener.controller;

import com.boot.springboot.component.listener.model.CallBackInfoEvent;
import com.boot.springboot.component.listener.model.RiskCallBackInput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author luowenjie
 * @since 2022/1/21 17:42
 */
@RestController
@RequestMapping("/listener")
public class ListenerController {

    @Autowired
    private ApplicationContext context;

    @RequestMapping(value = "/push/{text}", method = RequestMethod.GET)
    public String hello(@PathVariable("text") String text) {

        RiskCallBackInput input = new RiskCallBackInput ();
        input.setType(text);
        context.publishEvent(new CallBackInfoEvent(input));
        return text;
    }

}
